// var o;
// exports.GoodsConfig = exports.GoodsId = void 0;
// var r;
// var a;
// var AL_GAME_HUA_Common = require("./AL_GAME_HUA_Common");
// var AL_GAME_HUA_Define = require("./AL_GAME_HUA_Define");
// var AL_GAME_HUA_CurrencyData = require("./AL_GAME_HUA_CurrencyData");
// var AL_GAME_HUA_GameData = require("./AL_GAME_HUA_GameData");
// var AL_GAME_HUA_PayData = require("./AL_GAME_HUA_PayData");
// var AL_GAME_HUA_PlayerInfo = require("./AL_GAME_HUA_PlayerInfo");
// var AL_GAME_HUA_ConfigHandler = require("./AL_GAME_HUA_ConfigHandler");
// var AL_GAME_HUA_PropConfig = require("./AL_GAME_HUA_PropConfig");
// (a = r = exports.GoodsId || (exports.GoodsId = {}))[(a.gold = 0)] = "gold";
// a[(a.vit = 1)] = "vit";
// a[(a.prop_magicStick = 2)] = "prop_magicStick";
// a[(a.prop_overtime = 3)] = "prop_overtime";
// a[(a.prop_doubleStar = 4)] = "prop_doubleStar";
// a[(a.prop_prompt = 5)] = "prop_prompt";
// a[(a.prop_brush = 6)] = "prop_brush";
// a[(a.prop_freeze = 7)] = "prop_freeze";
// a[(a.prop_reset = 8)] = "prop_reset";
// a[(a.level_locking = 9)] = "level_locking";
// a[(a.level_empty = 10)] = "level_empty";
// a[(a.revive = 11)] = "revive";
// a[(a.shop_1 = 12)] = "shop_1";
// a[(a.shop_2 = 13)] = "shop_2";
// a[(a.shop_3 = 14)] = "shop_3";
// a[(a.shop_4 = 15)] = "shop_4";
// a[(a.shop_5 = 16)] = "shop_5";
// a[(a.shop_6 = 17)] = "shop_6";
// a[(a.shop_7 = 18)] = "shop_7";
// a[(a.shop_8 = 19)] = "shop_8";
// a[(a.star = 20)] = "star";
// a[(a.speedUp = 21)] = "speedUp";
// a[(a.no_ads = 22)] = "no_ads";
// a[(a.vip = 23)] = "vip";
// a[(a.shop_9 = 24)] = "shop_9";
// a[(a.medal = 25)] = "medal";
// var _ = (function (e) {
//     function t() {
//         return (null !== e && e.apply(this, arguments)) || this;
//     }
//     __extends(t, e);
//     t.getInstance = function () {
//         return this.instance || (this.instance = new t());
//     };
//     t.prototype.destroy = function () {
//         t.instance = null;
//     };
//     t.prototype.jiazai_peizhi = function () {
//         var e = this;
//         return this.yibu_jiazai_txt_peizhi("Goods").then(function (t) {
//             e.goodsConf = {};
//             var n = 0;
//             for (var o = t; n < o.length; n++) {
//                 var i = o[n];
//                 e.goodsConf[i.id] = i;
//             }
//         });
//     };
//     t.prototype.huoqu_shangpin_miaoshu = function (e) {
//         return this.goodsConf[e];
//     };
//     t.prototype.huoqu_shangpin_leixing = function (e) {
//         return this.goodsConf[e].type;
//     };
//     t.prototype.jiazai_tubiao_icon = function (e) {
//         var t = this;
//         return new Promise(function (n, o) {
//             var i = t.goodsConf[e];
//             if (i) {
//                 var r = i.icon;
//                 AL_GAME_HUA_Common.Common.loadRes({
//                     url: r,
//                     bundle: AL_GAME_HUA_Define.Define.GAME_NAME,
//                     type: cc.SpriteFrame
//                 }).then(function (t) {
//                     t.goodsId = e;
//                     n(t);
//                 });
//             } else {
//                 o();
//             }
//         });
//     };
//     t.prototype.jieshou_shangpin = function (e, t) {
//         switch ((e = Number(e))) {
//             case r.gold:
//                 AL_GAME_HUA_CurrencyData.CurrencyData.getInstance().tianjia_huobi({
//                     type: AL_GAME_HUA_CurrencyData.CurrencyType.COIN,
//                     num: t
//                 });
//                 break;
//             case r.vit:
//                 AL_GAME_HUA_CurrencyData.CurrencyData.getInstance().tianjia_huobi({
//                     type: AL_GAME_HUA_CurrencyData.CurrencyType.VIT,
//                     num: t
//                 });
//                 break;
//             case r.prop_magicStick:
//                 AL_GAME_HUA_GameData.GameData.getInstance().genggai_prop_shuliang(AL_GAME_HUA_PropConfig.PropId.TIPS_ENTER, t);
//                 break;
//             case r.prop_overtime:
//                 AL_GAME_HUA_GameData.GameData.getInstance().genggai_prop_shuliang(AL_GAME_HUA_PropConfig.PropId.TIME_ENTER, t);
//                 break;
//             case r.prop_doubleStar:
//                 AL_GAME_HUA_GameData.GameData.getInstance().genggai_prop_shuliang(AL_GAME_HUA_PropConfig.PropId.STAR_ENTER, t);
//                 break;
//             case r.prop_prompt:
//                 AL_GAME_HUA_GameData.GameData.getInstance().genggai_prop_shuliang(AL_GAME_HUA_PropConfig.PropId.TIPS_GAME, t);
//                 break;
//             case r.prop_brush:
//                 AL_GAME_HUA_GameData.GameData.getInstance().genggai_prop_shuliang(AL_GAME_HUA_PropConfig.PropId.CHANGE_GAME, t);
//                 break;
//             case r.prop_freeze:
//                 AL_GAME_HUA_GameData.GameData.getInstance().genggai_prop_shuliang(AL_GAME_HUA_PropConfig.PropId.TIME_GAME, t);
//                 break;
//             case r.prop_reset:
//                 AL_GAME_HUA_GameData.GameData.getInstance().genggai_prop_shuliang(AL_GAME_HUA_PropConfig.PropId.REFRESH_GAME, t);
//                 break;
//             case r.vip:
//                 AL_GAME_HUA_PayData.PayData.getInstance().huoqu_vip();
//                 break;
//             case r.medal:
//                 AL_GAME_HUA_PlayerInfo.PlayerInfo.getInstance().add_Medal(t);
//         }
//     };
//     t.instance = null;
//     return t;
// })(AL_GAME_HUA_ConfigHandler.ConfigHandler);
// exports.GoodsConfig = _;


// 引入模块
const AL_GAME_HUA_Common = require("./AL_GAME_HUA_Common");
const AL_GAME_HUA_Define = require("./AL_GAME_HUA_Define");
const AL_GAME_HUA_CurrencyData = require("./AL_GAME_HUA_CurrencyData");
const AL_GAME_HUA_GameData = require("./AL_GAME_HUA_GameData");
const AL_GAME_HUA_PayData = require("./AL_GAME_HUA_PayData");
const AL_GAME_HUA_PlayerInfo = require("./AL_GAME_HUA_PlayerInfo");
const AL_GAME_HUA_ConfigHandler = require("./AL_GAME_HUA_ConfigHandler");
const AL_GAME_HUA_PropConfig = require("./AL_GAME_HUA_PropConfig");

/** 商品ID的枚举类型 */
const GoodsId = {
    gold: 0,
    vit: 1,
    prop_magicStick: 2,
    prop_overtime: 3,
    prop_doubleStar: 4,
    prop_prompt: 5,
    prop_brush: 6,
    prop_freeze: 7,
    prop_reset: 8,
    level_locking: 9,
    level_empty: 10,
    revive: 11,
    shop_1: 12,
    shop_2: 13,
    shop_3: 14,
    shop_4: 15,
    shop_5: 16,
    shop_6: 17,
    shop_7: 18,
    shop_8: 19,
    star: 20,
    speedUp: 21,
    no_ads: 22,
    vip: 23,
    shop_9: 24,
    medal: 25
};

exports.GoodsId = GoodsId;

/** 商品配置类 */
class GoodsConfig extends AL_GAME_HUA_ConfigHandler.ConfigHandler {
    constructor() {
        super();
        this.goodsConf = {};
    }

    /** 获取单例实例 */
    static getInstance() {
        if (!GoodsConfig.instance) {
            GoodsConfig.instance = new GoodsConfig();
        }
        return GoodsConfig.instance;
    }

    /** 销毁实例 */
    destroy() {
        GoodsConfig.instance = null;
    }

    /** 加载商品配置 */
    async jiazai_peizhi() {
        try {
            const configData = await this.yibu_jiazai_txt_peizhi("Goods");
            this.goodsConf = {};

            let index = 0;
            for (const item of configData) {
                this.goodsConf[item.id] = item;
                index++;
            }
        } catch (error) {
            console.error("加载商品配置时出现错误: ", error);
        }
    }

    /** 获取商品描述 */
    huoqu_shangpin_miaoshu(goodId) {
        return this.goodsConf[goodId];
    }

    /** 获取商品类型 */
    huoqu_shangpin_leixing(goodId) {
        return this.goodsConf[goodId]?.type;
    }

    /** 加载商品图标 */
    jiazai_tubiao_icon(goodId) {
        return new Promise((resolve, reject) => {
            const goodsItem = this.goodsConf[goodId];
            if (goodsItem) {
                const iconUrl = goodsItem.icon;
                AL_GAME_HUA_Common.Common.loadRes({
                    url: iconUrl,
                    bundle: AL_GAME_HUA_Define.Define.GAME_NAME,
                    type: cc.SpriteFrame
                }).then(resource => {
                    resource.goodsId = goodId;
                    resolve(resource);
                });
            } else {
                reject();
            }
        });
    }

    /** 接收商品 */
    jieshou_shangpin(goodId, quantity) {
        const goodIdNumeric = Number(goodId);

        switch (goodIdNumeric) {
            case GoodsId.gold:
                AL_GAME_HUA_CurrencyData.CurrencyData.getInstance().tianjia_huobi({
                    type: AL_GAME_HUA_CurrencyData.CurrencyType.COIN,
                    num: quantity
                });
                break;
            case GoodsId.vit:
                AL_GAME_HUA_CurrencyData.CurrencyData.getInstance().tianjia_huobi({
                    type: AL_GAME_HUA_CurrencyData.CurrencyType.VIT,
                    num: quantity
                });
                break;
            case GoodsId.prop_magicStick:
                AL_GAME_HUA_GameData.GameData.getInstance().genggai_prop_shuliang(AL_GAME_HUA_PropConfig.PropId.TIPS_ENTER, quantity);
                break;
            case GoodsId.prop_overtime:
                AL_GAME_HUA_GameData.GameData.getInstance().genggai_prop_shuliang(AL_GAME_HUA_PropConfig.PropId.TIME_ENTER, quantity);
                break;
            case GoodsId.prop_doubleStar:
                AL_GAME_HUA_GameData.GameData.getInstance().genggai_prop_shuliang(AL_GAME_HUA_PropConfig.PropId.STAR_ENTER, quantity);
                break;
            case GoodsId.prop_prompt:
                AL_GAME_HUA_GameData.GameData.getInstance().genggai_prop_shuliang(AL_GAME_HUA_PropConfig.PropId.TIPS_GAME, quantity);
                break;
            case GoodsId.prop_brush:
                AL_GAME_HUA_GameData.GameData.getInstance().genggai_prop_shuliang(AL_GAME_HUA_PropConfig.PropId.CHANGE_GAME, quantity);
                break;
            case GoodsId.prop_freeze:
                AL_GAME_HUA_GameData.GameData.getInstance().genggai_prop_shuliang(AL_GAME_HUA_PropConfig.PropId.TIME_GAME, quantity);
                break;
            case GoodsId.prop_reset:
                AL_GAME_HUA_GameData.GameData.getInstance().genggai_prop_shuliang(AL_GAME_HUA_PropConfig.PropId.REFRESH_GAME, quantity);
                break;
            case GoodsId.vip:
                AL_GAME_HUA_PayData.PayData.getInstance().huoqu_vip();
                break;
            case GoodsId.medal:
                AL_GAME_HUA_PlayerInfo.PlayerInfo.getInstance().add_Medal(quantity);
                break;
        }
    }
}

// 设置单例实例为null
GoodsConfig.instance = null;
exports.GoodsConfig = GoodsConfig;